"""
列出所有用户脚本
"""
import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from app.core.database import SessionLocal
from app.models.user import User


def list_users():
    """列出所有用户"""
    db = SessionLocal()
    try:
        users = db.query(User).all()
        print('现有用户:')
        for user in users:
            print(f'用户名: {user.username}, 邮箱: {user.email}, 超级用户: {user.is_superuser}')
    except Exception as e:
        print(f"查询失败: {str(e)}")
    finally:
        db.close()


if __name__ == "__main__":
    list_users()